package com.heima.wemedia.controller.v1;

import com.heima.common.dtos.ResponseResult;
import com.heima.model.wemeida.dtos.WmNewsDto;
import com.heima.model.wemeida.dtos.WmNewsPageReqDto;
import com.heima.model.wemeida.pojos.WmNews;
import com.heima.wemedia.service.WmNewsService;
import org.omg.CORBA.INTERNAL;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/v1/news")
public class WmNewsController {
    @Autowired
    private WmNewsService wmNewsService;

    /**
     * 查询自媒体文章
     */
    @PostMapping("/list")
    public ResponseResult<List<WmNews>> findList(@RequestBody WmNewsPageReqDto dto){
        return wmNewsService.findList(dto);
    }

    /**
     * 发表文章
     */
    @PostMapping("/submit")
    public ResponseResult submit(@RequestBody WmNewsDto dto){
        return wmNewsService.submit(dto);
    }

    /**
     * 用于修改的回显
     */
    @GetMapping("/one/{id}")
    public ResponseResult<WmNews> findOne(@PathVariable("id") Integer id){
        return ResponseResult.okResult(wmNewsService.getById(id));
    }
}
